package com.yanqu.road.dataHelper.manager;

import com.yanqu.road.dao.db.DBManager;
import com.yanqu.road.dao.db.DatabaseMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

public class BaseMgr {

    static List<BaseMgr> mgrList = new ArrayList<>();

    public static void setMgrList(List<BaseMgr> list) {
        mgrList = list;
    }

    public static  <T> T getMgr(Class<T> T){
        for(BaseMgr baseMgr : mgrList){
            if(baseMgr.getClass() == T){
                return (T)baseMgr;
            }
        }
        return null;
    }

    protected static Logger logger = LogManager.getLogger(BaseMgr.class.getName());

    private final DBManager db;

    public BaseMgr() {
        db = DatabaseMgr.getDbManager();
    }

    public DBManager getDb() {
        return this.db;
    }

    public static Logger getLogger() {
        return logger;
    }

}
